<?php 

Class ModuleMembersStatResult extends CmsModule {
    public function __renderHead(){
		$filters = array('dateby', 'year', 'month', 'day');
		foreach($_GET as $k=>$v){
			if(in_array($k, $filters)){
				$$k = $v;
			}
		}
		$curr_datetime = date("Y-m-d H:i:s");
		$str_date=array();
		if ($year) {
			$str_date[] = $year;
		}
		if ($dateby !='month' && $month) {
			$str_date[] = $month;
		}
		if ($dateby == 'hour' && $day) {
			$str_date[] = $day;
		}
		$str_date = implode('-', $str_date);
		
		$data = $this->getData($dateby);
		
		$dateby = ucwords( strtolower($dateby));
		$this->contents = <<<HTML
	<div id="result" class="members_stat_result">
		<div class="hd">
			<div class="utility">
				<a href="#" class="print">Print</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				Export to <a href="#">HTML</a>
			</div>
			<hr />
			<h1>Members Stat Report</h1>
			<div class="time">{$curr_datetime}</div><br />
			<div><b>By {$dateby}:</b> {$str_date}</div>
		</div>
		<div class="bd">
		<br />
<table width="100%">
<tr class="weight" bgcolor="#CCCCCC"><td>分類</td><td>總數</td><td>百分比</td></tr>
<tr><td>會員總數 </td><td>{$data['total']['num']}</td><td>&nbsp;</td></tr>
<tr><td>新會員人數 </td><td>{$data['new']['num']}</td><td>{$data['new']['rate']}%</td></tr>
<tr><td>新會員有登錄過的人數 </td><td>{$data['new_logined']['num']}</td><td>{$data['new_logined']['rate']}%</td></tr>
<tr><td>舊會員人數 </td><td>{$data['old']['num']}</td><td>{$data['old']['rate']}%</td></tr>
<tr><td>舊會員導入後有登入過的人數 </td><td>{$data['old_logined']['num']}</td><td>{$data['old_logined']['rate']}%</td></tr>
<tr><td>新注冊人數 </td><td>{$data['new_reg']['num']}</td><td>&nbsp;</td></tr>
<tr><td>已注冊人數(未確認) </td><td>{$data['reged_not_confirm']['num']}</td><td>&nbsp;</td></tr>
</table>
		</div>
	</div>
HTML;
    }
    private function getData($dateby){
    	return array(
    		'total'=>array('num'=>rand(100, 9999)),
    		'new'=>array('num'=>rand(100, 9999), 'rate'=>rand(0, 100)),
    		'new_logined'=>array('num'=>rand(100, 9999), 'rate'=>rand(0, 100)),
    		'old'=>array('num'=>rand(100, 9999), 'rate'=>rand(0, 100)),
    		'old_logined'=>array('num'=>rand(100, 9999), 'rate'=>rand(0, 100)),
    		'new_reg'=>array('num'=>rand(100, 9999), 'rate'=>rand(0, 100)),
    		'reged_not_confirm'=>array('num'=>rand(100, 9999), 'rate'=>rand(0, 100)),
    	);
    }
}
?>